var windowName = "userBlock";
var list = new List();
var Page,load = 0
apiready = function(){
    onWindowShow(function () {
        var cur = getLocData("curUser")
        Page.curUser = cur;
        if (load > 0) {
            getData(Page);
        }
        load++
    })
    onWindowHide(function () {
    })
    console.log("index page is OK");
    Page = createVM("#Page",{
        //页面数据
        list:[]
        ,curUser:{}
    },{
        //页面方法
        "init":function () {
            // showLoading()
            // getCurFile(this)
            var cur = getLocData("curUser")
            this.curUser = cur;
            getData(Page)

        },
        'setCurFile': function (index) {
            var item = this.list[index];
            log(item.select)
            if (item.select == 1) {
                //删除
                this.list[index].select = 0;

                apiPost("/app/del/block",{id:item.id,user:this.curUser.User_id},function (res) {
                    logJson(res)
                    getData(Page)
                })
            }else {
                this.list[index].select = 1;

                apiPost("/app/add/block",{id:item.id,user:this.curUser.User_id},function (res) {
                    logJson(res)
                    getData(Page)
                })
            }
        }

    })

    Page.init()

}
function getData(_this) {
    apiGet("/app/blocks",{user:_this.curUser.User_id},function (res) {
        _this.list = res.data
    })
}